using NUnit.Framework;
using YatFram;
using YatFram.Browser.CssSelector;
using Yatfram.Tests.NunitExtensions;
using System.Linq;

namespace Yatfram.Tests.Browser
{
    public static class WatinBrowserAssertions
    {
        public static YatFram<Context> browser_dump_contains_the_text(this YatFram<Context> yf, string expectedText)
        {
            return yf.Check( context => context.Browser.Dump().AssertContains(expectedText));
        }

        public static YatFram<Context> browser_can_find_the_text_for(this YatFram<Context> yf, CssSelectors cssSelector, string expectedValue)
        {
            return yf.Check(context => Assert.That(context.Browser.Find(cssSelector).First().Text, Is.EqualTo(expectedValue)));
        }
        
        public static YatFram<Context> browser_can_find_the_value_for(this YatFram<Context> yf, string cssSelector, string expectedValue)
        {
            return yf.Check(context => Assert.That(context.Browser.FindTextBox(cssSelector).Value, Is.EqualTo(expectedValue)));
        }

        public static YatFram<Context> browser_can_find_the_class_for_textbox(this YatFram<Context> yf, string cssSelector, string className)
        {
            return yf.Check(context => Assert.That(context.Browser.FindTextBox(cssSelector).ClassNames.Contains(className)));
        }

        public static YatFram<Context> the_select_box_is_not_selected(this YatFram<Context> yf, string value, string cssSelector)
        {
            return yf.Check(context => Assert.That(context.Browser.FindSelect(cssSelector).SelectedValue, Is.Not.EqualTo(value)));
        }

        public static YatFram<Context> the_select_box_has_selected(this YatFram<Context> yf, string value, string cssSelector)
        {
            return yf.Check(context => Assert.That(context.Browser.FindSelect(cssSelector).SelectedValue, Is.EqualTo(value)));
        }

        public static YatFram<Context> a_radio_option_not_selected_is(this YatFram<Context> yf, string value, string name)
        {
            return yf.Check(context => Assert.That(context.Browser.FindRadio(name).SelectedValue, Is.Not.EqualTo(value)));
        }

        public static YatFram<Context> the_radio_option_selected_is(this YatFram<Context> yf, string value, string name)
        {
            return yf.Check(context => Assert.That(context.Browser.FindRadio(name).SelectedValue, Is.EqualTo(value)));
        }
        public static YatFram<Context> the_checkbox_option_checked_is(this YatFram<Context> yf, string value, string name)
        {
            return yf.Check(context => Assert.That(context.Browser.FindCheckbox(name).CheckedValues.Contains(value)));
        }
        public static YatFram<Context> a_checkbox_option_not_checked_is(this YatFram<Context> yf, string value, string name)
        {
            return yf.Check(context => Assert.That(context.Browser.FindCheckbox(name).CheckedValues.Contains(value), Is.False));
        }
    }
}